﻿/*
 * Message.h
 */

//**************************************************
#undef DECLARE_MESSAGE_BEGIN
#undef DECLARE_MESSAGE_MEMBER
#undef DECLARE_MESSAGE_INIT
#undef DECLARE_MESSAGE_END


//**************************************************
#if defined(IMPLEMENT_MESSAGE_MTBL)

#	define DECLARE_MESSAGE_BEGIN(className, baseClass) \
			IMPLEMENT_RT_CREATOR(className)\
			IMPLEMENT_MTBL_BEGIN(className)\
			IMPLEMENT_MTBL_SUPPER(baseClass)

#	define DECLARE_MESSAGE_MEMBER(type, name) \
			IMPLEMENT_MTBL_MEMBER(name)

#	define DECLARE_MESSAGE_INIT(name, value)

#	define DECLARE_MESSAGE_END() \
			IMPLEMENT_MTBL_END()


//**************************************************
#elif defined(IMPLEMENT_MESSAGE_PROPERTY)

#	define DECLARE_MESSAGE_BEGIN(className, baseClass) \
			REGISTER_PROPERTY_CONVERTER_OBJECT(className)\
			IMPLEMENT_PROPERTY_BEGIN1(className, baseClass)

#	define DECLARE_MESSAGE_MEMBER(type, name) \
			IMPLEMENT_PROPERTY_ATTRIBUTE(name, __TEXT__(#name))

#	define DECLARE_MESSAGE_INIT(name, value)

#	define DECLARE_MESSAGE_END() \
			IMPLEMENT_PROPERTY_END()


//**************************************************
#elif defined(IMPLEMENT_MESSAGE_INIT)

#	define DECLARE_MESSAGE_BEGIN(className, baseClass) \
			className::className(void)\
				: baseClass()

#	define DECLARE_MESSAGE_MEMBER(type, name) 

#	define DECLARE_MESSAGE_INIT(name, value) \
				, name(value)

#	define DECLARE_MESSAGE_END() \
			{}


//**************************************************
#elif defined(REGISTER_MESSAGE)

#	define DECLARE_MESSAGE_BEGIN(className, baseClass) \
			REGISTER_RT_CREATOR(className)\
			REGISTER_PROPERTY(className)

#	define DECLARE_MESSAGE_MEMBER(type, name) 

#	define DECLARE_MESSAGE_INIT(name, value)

#	define DECLARE_MESSAGE_END() 


//**************************************************
#else


	//---------------------------------------------
#	define DECLARE_MESSAGE_BEGIN(className,baseClass) \
			typedef gdk::Unknown::Handle_T<class className> className##Ptr;\
			class className : public baseClass\
			{\
				DECLARE_CLASS_HANDLE(className)\
				DECLARE_CLASS_INSTANCE(className)\
				DECLARE_CLASS_SERIALIZE(className)\
				DECLARE_RT_CREATOR(className)\
				DECLARE_PROPERTY(className)\
				DECLARE_MTBL(className)\
				DECLARE_MESSAGE_PARSE(className)\
			private:\
				className(void);\
			public:

#	define DECLARE_MESSAGE_MEMBER(type, name) \
				type name;

#	define DECLARE_MESSAGE_INIT(name, value)

#	define DECLARE_MESSAGE_END() \
			};


#ifndef __GDK_MESSAGE_H__
#define __GDK_MESSAGE_H__


#include <gdk/core/Types.h>
#include <gdk/core/Mtbl.h>
#include <gdk/core/Property.h>
#include <gdk/core/Exception.h>
#include <gdk/core/Stream.h>



namespace gdk
{


	//---------------------------------------------
#define DECLARE_MESSAGE_PARSE(className) \
		public:\
			static gdk::Unknown::Handle_T<gdk::Message> createMessage_(void)\
				{ return GDK_NEW className(); }\
		private:


	//---------------------------------------------
	class GDK_CORE_EXPORT Message : public Property
	{
		DECLARE_CLASS_HANDLE(Message)
		DECLARE_CLASS_INSTANCE(Message)
		DECLARE_CLASS_SERIALIZE(Message)
		DECLARE_RT_CREATOR(Message)
		DECLARE_PROPERTY(Message)
		DECLARE_MESSAGE_PARSE(Message)

	protected:
		__INLINE__ Message(void)
		{}
	};


	template<typename TyIs>
	__INLINE__ TyIs& operator >>(TyIs &is, Message &msg) __THROW1
	{
		return is >> (Property&)msg;
	}
	template<typename TyOs>
	__INLINE__ TyOs& operator <<(TyOs &os, Message const &msg) __THROW1
	{
		return os << (const Property&)msg;
	}



}//namespace gdk


#endif //__GDK_MESSAGE_H__


//**************************************************
#endif
